#-------------------------------------------------------------------
# Project Invasion of the aliens 
# name game.py
# purpose Player AI
#
# authors Chris L'Heureux, Tyler Plante, Jackson Morse
# main author Chris L'Heureux,
#
# created 12/3/12
# Copyright (C) Chris L'Heureux,
# License New BSD\
#------------------------------------------------------------------  
import pygame, math, sys, random

class Player():
    def __init__(self, speed, position):
        self.baseSurfaces = []
        self.baseSurfaces += [pygame.image.load("Game Image/Player1.png")]
        self.frame = 0
        self.maxFrame = len(self.baseSurfaces)-1
        self.surface = self.baseSurfaces[self.frame]
        self.rect = self.surface.get_rect()
        self.baseRect = self.rect
        self.radius = (self.rect.width/2 + self.rect.height/2)/2
        self.angle = 0
        self.speed = 1
        self.maxSpeed = speed 
        self.place(position)
        self.living = True
        self.dir = "none"
        self.heading = "s"
        self.x = position[0]
        self.realx = 0
        self.y = position[0]
        self.realy = 0
        self.scrollThreshold = 250
        self.scrolling = False
        self.x = self.rect.center[0]
        self.y = self.rect.center[1]
        self.noSpeed = 0
        
        self.screenWidth = 1024
        self.screenHeight = 768
        
        if pygame.mixer:
            self.bounceSound = pygame.mixer.Sound("")
            
                    
        
    def  __str__(self):
        return ("I'm the Player and i am LIVING " + str(self.rect.center) + str(self.speed) + str(self.living))
     
    def die(self):
        self.living = False
     
    def place(self, position):
        self.rect.center = position
        
    def direction(self, dir):
        if dir == "climb up":
            self.speed = -self.maxSpeed
            self.dir = dir
            self.heading = "n"
        elif dir == "climb down":
            self.speed = self.maxSpeed
            self.dir = dir
            self.heading = "s"
        elif dir == "stop up":
            self.speed = self.noSpeed
            self.dir = dir
        elif dir == "stop down":
            self.speed = self.noSpeed
            self.dir = dir
            
        if dir == "right":
            self.speed = self.maxSpeed
            self.dir = dir
            self.heading = "e"
        elif dir == "left":
            self.speed = -self.maxSpeed
            self.dir = dir
            self.heading = "w"
        elif dir == "stop right":
            self.speed = self.noSpeed
            self.dir = dir
        elif dir == "stop left":
            self.speed = self.noSpeed
            self.dir = dir
    
    def move(self):
        self.realx += self.speed
        self.x += self.speed
        if self.x >= self.screenWidth - self.scrollThreshold:
            self.x = self.screenWidth - self.scrollThreshold
            self.scrolling = True
        elif self.x <= self.scrollThreshold:
            self.x = self.scrollThreshold
            self.scrolling = True
        else:
            self.scrolling = False
        
        self.realy += self.speed
        self.y += self.speed
        if self.y >= self.screenHeight - self.scrollThreshold:
            self.y = self.screenHeight - self.scrollThreshold
            self.scrolling = True
        elif self.y <= self.scrollThreshold:
            self.y = self.scrollThreshold
            self.scrolling = True
        else:
            self.scrolling = False  
            
        self.place([self.x, self.realy]) 
        
    def DistanceToPoint():
        x1 = self.rect.center[0]
        x2 = pt[0]
        y1 = self.rect.center[1]
        y2 = pt[1]
        return math.sqrt(((x2-x1)**2)+((y2-y1)**2))\
        
    def wallCollide(self, screenWidth, screenHeight):
        if (self.rect.left < 0 or self.rect.right > screenWidth):
                self.die()
        if (self.rect.top < 0 or self.rect.top > screenHeight):
                self.die()
                
        #print "trying to hit ", str(other)

    def update(*args):
        self = args[0]
        if not self.living:
            self.kill()
        self.move()
        self.direction()
        self.wallCollide()
        
    #TEST    
    
    